/* 
 *  <copyright file="ScrollingBackground.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

using SobrietyEngine.Actor;
using SobrietyEngine.Components;
using SobrietyEngine.Common;
using SobrietyEngine.Textures;

namespace SobrietyEngine.Components.Graphic2D
{
    public class ScrollingBackground:TextureComponent, SobrietyEngine.Components.IComponent
    {
        Vector2 scrollAmount = new Vector2(0,0);
        //float nextScroll = 0.0f;
        //float scrollSpeed = 75.0f;
        Rectangle surface;

        public ScrollingBackground():base()
        {
        }

        override public void Set(Parameters parms)
        {
            base.Set(parms);
            Rectangle surfSize = (Rectangle)parms["Surface"];
            surface = new Rectangle(surfSize.X - 2000, surfSize.Y - 2000, surfSize.Width + 4000, surfSize.Height + 4000);
        }

        public new void Update(GameTime elapsedTime)
        {
            /*
            nextScroll -= elapsedTime.ElapsedGameTime.Milliseconds;
            if (nextScroll < 0)
                nextScroll = 0;
            if (nextScroll == 0)
            {
                position.Add(scrollAmount);
                nextScroll += scrollSpeed;
                if (position.Get().X>= surface.Right)
                    position.Set(new Vector2(0,0));
            }*/
            base.Update(elapsedTime);
        }

        Vector2 pos;
        public override void Draw(SpriteBatch spriteBatch)
        {
            pos = position.Get();
            for (int x = surface.Left - (int)pos.X; x < surface.Right; x+= spriteTexture.Width)
            {
                for (int y = surface.Top - (int)pos.Y; y < surface.Bottom; y+=spriteTexture.Height)
                {
                    spriteBatch.Draw(spriteTexture, new Vector2(x, y), new Rectangle(0,0,spriteTexture.Width, spriteTexture.Height),Color, 0, new Vector2(0,0), 1.0f, SpriteEffects.None, layer);
                }
            }
            /*
            if (rotation != null)
            {
                rot = rotation.GetRadians();
                rotationOrigin = rotation.RotationOrigin;
            }

            if (scale != null)
                scl = (float)scale.Get().X;

                SpriteEffects effects = SpriteEffects.None;
                if (flipImageHorz)
                    effects |= SpriteEffects.FlipHorizontally;
                if (flipImageVert)
                    effects |= SpriteEffects.FlipVertically;

                spriteBatch.Draw(
                    spriteTexture, 
                    position.Get() - rotationOrigin,
                new Rectangle(0, 0, spriteTexture.Width, spriteTexture.Height),
                Color,
                rot,
                //This is the center point of the rotation
                SpriteHalfSize - rotationOrigin,
                //This is the scaling
                scl,
                effects,
                //this is the layer
                layer);                
            }*/
        }
    }
}